package com.ghost.alibabaghost.dao.mapper.sys;

import com.ghost.alibabaghost.dao.dataobject.sys.GhostDictDO;
import org.apache.ibatis.annotations.*;

import java.util.List;

/**
 * @author yaolisheng
 * @version 1.0
 * @date 2022/1/24 06:31
 */
@Mapper
public interface GhostDictMapper {

    /**
     * @param parentCode
     * @return
     */
    @Select("select id,dict_name,dict_code,parent_code,remarks from ghost_dict where parent_code = #{parentCode}")
    List<GhostDictDO> queryByParentCode(@Param("parentCode") String parentCode);

    /**
     * @param ghostDictDO
     * @return
     */
    @Insert("insert into ghost_dict(dict_name,dict_code,parent_code,remarks)values(#{dictName},#{dictCode},#{parentCode},#{remarks})")
    Integer insertDict(GhostDictDO ghostDictDO);

    /**
     * @param id
     * @return
     */
    @Delete("delete from ghost_dict where id = #{id}")
    Integer deleteByDictCode(@Param("dictCode") Integer id);

    /**
     * @param parentCode
     * @return
     */
    @Select("select * from ghost_dict where parent_code=#{parentCode}")
    @Results(id = "tree" , value = {
            @Result(property = "id" , column = "id"),
            @Result(property = "dictName" , column = "dict_name"),
            @Result(property = "dictCode" , column = "dict_code"),
            @Result(property = "parentCode" , column = "parent_code"),
            @Result(property = "remarks" , column = "remarks"),
            @Result(property = "subDict" , column = "dict_code" , many = @Many(select = "getTreeByParentCode")),
    })
    List<GhostDictDO> getTreeList(String parentCode);

    /**
     * @param parentCode
     * @return
     */
    @Select("select * from ghost_dict where parent_code = #{parentCode}")
    @ResultMap("tree")
    List<GhostDictDO> getTreeByParentCode(String parentCode);
}
